/**
 * 
 */
package com.nashuju.app.controller;

import java.io.File;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.codec.digest.Md5Crypt;
import org.durcframework.core.DefaultGridResult;
import org.durcframework.core.GridResult;
import org.durcframework.core.UserContext;
import org.durcframework.core.ValidateHolder;
import org.durcframework.core.controller.BaseController;
import org.durcframework.core.expression.Expression;
import org.durcframework.core.expression.ExpressionQuery;
import org.durcframework.core.expression.SqlContent;
import org.durcframework.core.expression.subexpression.SqlExpression;
import org.durcframework.core.expression.subexpression.ValueExpression;
import org.durcframework.core.util.ValidateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.google.gson.Gson;
import com.nashuju.app.api.JPush;
import com.nashuju.app.entity.ReqFeedBack;
import com.nashuju.app.entity.ReqReceipt;
import com.nashuju.app.entity.ReqReimburse;
import com.nashuju.app.entity.ReqTicket;
import com.nashuju.web.common.Config;
import com.nashuju.web.common.Md5Encrypt;
import com.nashuju.web.common.RMSContext;
import com.nashuju.web.entity.sw.RUser;
import com.nashuju.web.entity.sw.RUserSch;
import com.nashuju.web.entity.sw.SConstract;
import com.nashuju.web.entity.sw.SConstractSch;
import com.nashuju.web.entity.sw.SContact;
import com.nashuju.web.entity.sw.SContactSch;
import com.nashuju.web.entity.sw.SCustomer;
import com.nashuju.web.entity.sw.SCustomerSch;
import com.nashuju.web.entity.sw.SIndustryConfig;
import com.nashuju.web.entity.sw.SIndustryConfigSch;
import com.nashuju.web.entity.sw.SMessage;
import com.nashuju.web.entity.sw.SMessageSch;
import com.nashuju.web.entity.sw.SReceipt;
import com.nashuju.web.entity.sw.SReceiptSch;
import com.nashuju.web.entity.sw.SReimburse;
import com.nashuju.web.entity.sw.SReimburseSch;
import com.nashuju.web.service.sw.SReimburseService;
import com.nashuju.web.entity.sw.STaskSchedule;
import com.nashuju.web.entity.sw.STaskScheduleSch;
import com.nashuju.web.entity.sys.SysClass;
import com.nashuju.web.entity.sys.SysClassSch;
import com.nashuju.web.entity.sys.SysUpload;
import com.nashuju.web.entity.sys.SysUploadSch;
import com.nashuju.web.entity.user.User;
import com.nashuju.web.entity.user.UserSch;
import com.nashuju.web.service.sw.RUserService;
import com.nashuju.web.service.sw.SAssociationRecordService;
import com.nashuju.web.service.sw.SCompanyService;
import com.nashuju.web.service.sw.SConstractService;
import com.nashuju.web.service.sw.SContactService;
import com.nashuju.web.service.sw.SCustomerService;
import com.nashuju.web.service.sw.SIndustryConfigService;
import com.nashuju.web.service.sw.SMessageService;
import com.nashuju.web.service.sw.SReceiptService;
import com.nashuju.web.service.sw.STaskScheduleService;
import com.nashuju.web.service.sys.SysClassService;
import com.nashuju.web.service.sys.SysUploadService;
import com.nashuju.web.service.user.UserService;
import com.nashuju.web.util.PasswordHash;
import com.nashuju.web.util.PasswordUtil;
import com.nashuju.web.util.TimeUtil;

/**
 * @author xiaoren
 *
 */
@Controller
@RequestMapping(value = "/app")
public class indexController extends BaseController {

	@Autowired
    private UserService UserService;
	@Autowired
    private RUserService rUserService;
	
	@Autowired
	private UserService userService;
	@Autowired
	private SConstractService sConstractService;
	@Autowired
	private STaskScheduleService sTaskScheduleService;
	@Autowired
	private SCompanyService sCompanyService;
	@Autowired
	private SReceiptService SReceiptService;
	@Autowired
	private SReimburseService sReimburseService;
	@Autowired
	private SIndustryConfigService sIndustryConfigService;
	@Autowired
	private SCustomerService sCustomerService;
	@Autowired
	private SMessageService sMessageService;
	@Autowired
	private SAssociationRecordService sAssociationRecordService;
	@Autowired
	private SContactService sContactService;
	@Autowired
	private SysUploadService sysUploadService;
	@Autowired
	private SysClassService sysClassService;

	public indexController() {
	}


	@RequestMapping(value = "/login.do" )
    public @ResponseBody Map<String, Object> login(@RequestBody RUserSch backUserSch) {

		Map<String, Object> res = new HashMap();
		GridResult result = new DefaultGridResult();
		String password = backUserSch.getPasswordSch();
		String bundleId = null;
		
		System.out.println(backUserSch.getBundleIdSch());
		
		if (backUserSch.getBundleIdSch()!=null && backUserSch.getUsernameSch()!=null) {
			bundleId = backUserSch.getBundleIdSch();
		}
		
		backUserSch.setBundleIdSch(null);
		backUserSch.setPasswordSch(null);
		
		List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(backUserSch));
		List<String> log = new ArrayList<String>();
		
        ValidateHolder validateHolder = ValidateUtil.validate(backUserSch);
        if (validateHolder.isSuccess()) {
            if (StringUtils.hasText(backUserSch.getUsernameSch())) {
                User user = UserService.getByUserName(backUserSch.getUsernameSch());
                if (user == null) {
                	res.put( "success", "false");
                    return res;
                }

                String correctHash = user.getPassword();
                boolean isPswdCorrect = PasswordUtil.validatePassword(password, correctHash);

                if (isPswdCorrect) {
                    doLogin(user);
                    res.put( "success", "true");

                    if (listRUser.size()>0) 
                    {
                    	if (bundleId!=null) {
                    		listRUser.get(0).setBundleId(bundleId);
                    		listRUser.get(0).setIsLogin(true);
                    		rUserService.update(listRUser.get(0));
                    		
                    		SMessageSch messageSch  = new SMessageSch();
    						messageSch.setStatusSch("unsent");
    						List<SMessage> msgList = sMessageService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(messageSch));
    						for (int i = 0; i < msgList.size(); i++) {
    							JPush.alertByRegistrationId(bundleId, msgList.get(i).getWorkRecord(),new Gson().toJson(msgList.get(i)));
    							JPush.alertByRegistrationIdForiOS(bundleId,msgList.get(i).getWorkRecord(),msgList.get(i).getTaskId());
    							msgList.get(i).setStatus("sent");
    							sMessageService.update(msgList.get(i));
    						}
                    		
						}
                      res.put("user", listRUser.get(0));
					}
                   
                    return res;
                }
            }
        }

        res.put( "success", "false");
        return res;
    }
	
	@RequestMapping("/loginOut.do")
    public @ResponseBody Map<String, Object>  loginOut(@RequestBody  RUserSch backUserSch) {
		Map<String, Object> res = new HashMap();
		Map<String, Object> result = new HashMap();
		List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(backUserSch));
//		SMessageSch messageSch = new SMessageSch();
//		messageSch.setReceiveIdSch(receiveIdSch);
//		List<SMessage> listMessage = sMessageService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(backUserSch));
		listRUser.get(0).setIsLogin(false);
		rUserService.update(listRUser.get(0));
		result.put("success", "true");
		res.put("success", "true");
		res.put("result", result);
		//res.put("account", value);
		return res;
	}
	
	@RequestMapping("/updataPassword.do")
    public @ResponseBody Map<String, Object>  updataPassword(@RequestBody RUserSch backUserSch) throws NoSuchAlgorithmException, InvalidKeySpecException {
		Map<String, Object> res = new HashMap();
		Map<String, Object> result = new HashMap();
		List<String> log = new ArrayList<String>();
		String newpwd = PasswordUtil.createStorePswd(backUserSch.getPasswordSch());
		RUserSch userSch = new RUserSch();
		userSch.setUsernameSch(backUserSch.getUsernameSch());
		List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(userSch));
		boolean isPswdCorrect = PasswordUtil.validatePassword(Md5Encrypt.encrypt(backUserSch.getOldPwdSch()), listRUser.get(0).getPassword());
		if(isPswdCorrect)
		{
			result.put("isPswdCorrect", "true");
			log.add("isPswdCorrect is right");
			listRUser.get(0).setPassword(newpwd);
			rUserService.update(listRUser.get(0));
			res.put("message", log);
			res.put("result", result);
			res.put("success", "true");
		}
		else 
		{
			log.add("isPswdCorrect is not right");
			result.put("isPswdCorrect", "false");
			res.put("result", result);
			res.put("message", log);
			res.put("success", "false");
		}
		
		return res;
	}
	
	
	private void doLogin(User user) {
        // 缓存当前用户角色权限
        RMSContext.getInstance().refreshUserRightData(user.getUsername());

        user.setLastLoginDate(new Date());
        UserContext.getInstance().setUser(user);
        try {
        	 UserService.update(user);
		} catch (Exception e) {
			e.printStackTrace();
		}
        UserService.update(user);
    }
	
	//条件查询并返回所有记录
	@RequestMapping("/listSUser.do")
    public @ResponseBody Map<String, Object>  listAllSTask(@RequestBody RUserSch searchEntitySch) {
		Map<String, Object> res = new HashMap();
		GridResult result = new DefaultGridResult();
		List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(searchEntitySch));
		result.setList(listRUser);
		res.put("result", result);
		//res.put("account", value);
		return res;
    }
		

		//条件查询并返回所有记录
		@RequestMapping("/setTaskDoing.do")
	    public @ResponseBody Map<String, Object>  setTaskDoing(@RequestBody STaskScheduleSch searchEntitySch) {
			Map<String, Object> res = new HashMap();
			List<STaskSchedule> listSTaskSchdule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(searchEntitySch));
			listSTaskSchdule.get(0).setStatus(Config.DEALING);
			sTaskScheduleService.update(listSTaskSchdule.get(0));
			res.put("success", "true");
			return res;
	    }
		
		
		//条件查询并返回所有记录
		@RequestMapping("/setMessageRead.do")
	    public @ResponseBody Map<String, Object>  setMessageRead(@RequestBody SMessage SMessage) {
			Map<String, Object> res = new HashMap();
			if (SMessage.getId()!=null) {
				SMessage.setIsRead("1");
				sMessageService.update(SMessage);
				res.put("success", "true");
				return res;
			}
			else
			{
				res.put("Message", "id is null");
				res.put("success", "false");
				return res;
			}
	    }
		
		//按照用户名获取任务列表
		@RequestMapping("/listSTaskByusernameSch.do")
		public @ResponseBody
		Map<String, Object> listSTaskSchedule (@RequestBody RUserSch rUserSch ) {
			
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			
			//获取用户列表
			List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
			
			//获取任务列表
			ExpressionQuery query = ExpressionQuery.buildQueryAll();
			List<Expression> expressions = new ArrayList<Expression>();
			if (rUserSch.getStatusSch().equals("已发布")) {
				expressions.add(new ValueExpression("executor_id",SqlContent.EQUAL, listRUser.get(0).getId()));
				expressions.add(new SqlExpression(SqlContent.AND,"(status = '已发布' or status = '执行中')"));
				query.addAll(expressions);
			}
			else
			{
				expressions.add(new ValueExpression("executor_id",SqlContent.EQUAL, listRUser.get(0).getId()));
				expressions.add(new SqlExpression(SqlContent.AND,"(status = '已完成' or status = '已回访' or status = '已归档'or status = '已审核') "));
				query.addAll(expressions);
			}
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(query);
			
			try {
				for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
					
					//获取客户列表
					SCustomerSch sCustomerSch = new SCustomerSch();
					sCustomerSch.setIdSch(sTaskSchedule.getCustomerId());
					List<SCustomer> listsCustomer = sCustomerService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sCustomerSch));
					sTaskSchedule.setsCustomers(listsCustomer);
					
					//获取合同列表
					SConstractSch ConstractEntitySch = new SConstractSch();
					ConstractEntitySch.setIdSch(sTaskSchedule.getContractId());
					List<SConstract> listSConstract = sConstractService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(ConstractEntitySch));
					sTaskSchedule.setsConstracts(listSConstract);
					
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		
			result.put("taskSchedule", listSTaskSchedule);
			res.put("success", "true");
			res.put("result", result);
			res.put("message", log);
			
			return res;
		}



		/*****************************************************************************
		* @author         :xiaoren 
		* @version        : V1.0
		* @param          : User
		* @Description    : 按照用户名获取合同列表
		* @Date           : 2016年4月29日 下午1:06:09    
		******************************************************************************/
		@RequestMapping("/listSConstratByUserNameSch.do")
		public @ResponseBody
		Map<String, Object> listSConstratSchedule(@RequestBody RUserSch rUserSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();			
			List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
			List<String> log = new ArrayList<String>();
			if (listRUser.size()>0) {
			 	
			//获取任务列表
			STaskScheduleSch searchEntitySch = new STaskScheduleSch();
			searchEntitySch.setExecutorIdSch(listRUser.get(0).getId());
			searchEntitySch.setStatusSch(rUserSch.getStatusSch());
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(searchEntitySch));
			List<Integer> ConstractIds = new ArrayList<>();
			List<SConstract> listSConstract = new ArrayList<>();
			
			for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
				//获取客户列表
				SCustomerSch sCustomerSch = new SCustomerSch();
				sCustomerSch.setIdSch(sTaskSchedule.getCustomerId());
				List<SCustomer> listsCustomer = sCustomerService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sCustomerSch));
					
				try {
					if (ConstractIds.indexOf(listsCustomer.get(0).getId()) == -1) {
						//根据客户找到合同并添加到合同列表中
						 SConstractSch sConstractSch = new SConstractSch();
						 sConstractSch.setCustomerIdSch(listsCustomer.get(0).getId());
						 listSConstract.add(sConstractService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sConstractSch)).get(0));
						 ConstractIds.add(listsCustomer.get(0).getId());
					}
				} catch (Exception e) {
					log.add("未能根据客户找到合同，请为"+listsCustomer.get(0).getFullName()+"绑定合同");
				}
				
				 
			}
				
			
			 
			for (SConstract sConstract : listSConstract) {
				// 获取报销列表
				SReceiptSch sReceiptSch = new SReceiptSch();
				sReceiptSch.setConstractIdSch(sConstract.getId());
				List<SReceipt> listReceipt = SReceiptService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sReceiptSch));
				sConstract.setSReceipts(listReceipt);
				
				//获取任务列表
				STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
				sTaskScheduleSch.setContractIdSch(sConstract.getId());
				List<STaskSchedule> listSTaskSchedule1 = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
				sConstract.setsTaskSchedules(listSTaskSchedule1);
				
				//获取费用列表
				SReimburseSch SReimburseSch = new SReimburseSch();
				SReimburseSch.setConstractIdSch(sConstract.getId());
				List<SReimburse> listSReimburse = sReimburseService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(SReimburseSch));
				sConstract.setsReimburses(listSReimburse);
				
				//获取配置列表
				SIndustryConfigSch SIndustryConfigSch = new SIndustryConfigSch();
				SIndustryConfigSch.setConstractIdSch(sConstract.getId());
				List<SIndustryConfig> listSIndustryConfig = sIndustryConfigService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(SIndustryConfigSch));
				sConstract.setsIndustryConfigs(listSIndustryConfig);
				
				
				
			}
			result.put("constract",listSConstract);		
			}
			res.put("success", "true");
			res.put("result", result);
			res.put("message", log);
			return res;
		}
		
		
		@RequestMapping("/exsitTask.do")
		public @ResponseBody
		Map<String, Object> exsitTask(@RequestBody RUserSch  rUserSch) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();			
			List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
			List<String> log = new ArrayList<String>();
			if (listRUser.size()>0) {
			 	
				List<STaskSchedule>  taskSchedule = (List<STaskSchedule>)Config.cSql.excutSql("select * from s_task_schedule where (status ='已发布' or status ='执行中') "+"AND executor_id ="+listRUser.get(0).getId()+" ORDER BY edited_time desc limit 1",new STaskSchedule());
				if (taskSchedule.size()!=0) {
					result.put("exsit", "true");
					result.put("recentTask",taskSchedule.get(0).getId());
				}
				else{
				
					result.put("exsit", "false");
				}
			
			}
			else
			{
				log.add("用户不存在！");
			}
			
			res.put("success", "true");
			res.put("result", result);
			res.put("message", log);
			return res;
			
		}

		
		/*****************************************************************************
		* @author         :xiaoren 
		* @version        : V1.0
		* @param          : ｛vistRecordSch:abc , serviceRecordSch:bbb, evaluationSch:aaa, rateSch:5｝
		* @Description    : 按照 taskIdSch  传反馈意见  评价接口
		* @Date           : 2016年4月29日 下午1:06:09    
		******************************************************************************/
		@RequestMapping("/addVistRecord.do")
		public @ResponseBody
		Map<String, Object> addVistRecord(@RequestBody STaskScheduleSch taskScheduleSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			STaskScheduleSch taskScheduleSch1 = new STaskScheduleSch();
			taskScheduleSch1.setIdSch(taskScheduleSch.getIdSch());
			List<STaskSchedule> listTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(taskScheduleSch1));
			List<String> log = new ArrayList<String>();
			try {
				if (listTaskSchedule.size()>0) {
					STaskSchedule sTaskSchedule =listTaskSchedule.get(0);
					sTaskSchedule.setVisiteRecord(taskScheduleSch.getVisiteRecordSch());
					sTaskSchedule.setServiceRecord(taskScheduleSch.getServiceRecordSch());
					sTaskSchedule.setServiceRecord(taskScheduleSch.getServiceRecordSch());
					sTaskSchedule.setEvaluation(taskScheduleSch.getEvaluationSch());
					sTaskSchedule.setRate(taskScheduleSch.getRateSch());
					sTaskSchedule.setRealFinishTime(new Date());
					sTaskSchedule.setStatus(Config.FINISHED);
					sTaskScheduleService.update(sTaskSchedule);
					
				}
				
				res.put("success", "true");
				return res;
			} catch (Exception e) {
				res.put("success", "false");
				e.printStackTrace();
				return res;
				
			}
		}
		
		/*
		 * 
		 * 
		 * 
		 * 
		 *
		 * */
		@RequestMapping("/getIndexInfo.do")
		public @ResponseBody
		Map<String, Object> getIndexInfo(@RequestBody RUserSch rUserSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
			List<String> log = new ArrayList<String>();
			try {
				if (listRUser.size()>0) {
					RUser user = listRUser.get(0);
					
					//获取任务数
					STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
					
					sTaskScheduleSch.setExecutorIdSch(user.getId());
					List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
					int taskNum = listSTaskSchedule.size();
					
					ExpressionQuery query = ExpressionQuery.buildQueryAll();
					List<Expression> expressions = new ArrayList<Expression>();
					expressions.add(new ValueExpression("executor_id",SqlContent.EQUAL, user.getId()));
					expressions.add(new SqlExpression(SqlContent.AND,"(status = '已完成' or status = '已审核' or status = '已归档')"));
					query.addAll(expressions);
					
					int realTaskNum = sTaskScheduleService.find(query).size();
					
					// realTaskNumber 已经完成的任务数量 
					// taskNumber 总共的任务数量
					result.put("realTaskNumber", realTaskNum);
					result.put("taskNumber", taskNum);
					
					//获取工时 已完成的工时 taskHours  
					int taskHours = 0; int realTaskHours = 0;
					for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
						if (sTaskSchedule.getStatus().equals("Config.FINISHED")||sTaskSchedule.getStatus().equals("Config.CHECKED")||sTaskSchedule.getStatus().equals("Config.ARCHIVE")) {
							if (sTaskSchedule.getWorkHours() != null) {
								realTaskHours += Integer.parseInt(sTaskSchedule.getWorkHours());
							}
						}
						
					}
					for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
						taskHours += Integer.parseInt(sTaskSchedule.getWorkHours());
					}
					result.put("realTaskHours", realTaskHours);
					result.put("taskHours", taskHours);
					
					//获取信息
					SMessageSch messageSch = new SMessageSch();
					messageSch.setUserIdSch(user.getId());
					int messageNumber = sMessageService.findTotalCount(ExpressionQuery.buildQueryAll().addAnnotionExpression(messageSch));
					
					int readMessageNumber = 1;
					if (messageNumber == 0) {
						messageNumber = 2;
					}
					result.put("readMessageNumber", readMessageNumber);
					result.put("messageNumber", messageNumber);
					
					//获取金额总数	
					 SConstractSch sConstractSch = new SConstractSch();
					 sConstractSch.setEngineerSch(listRUser.get(0).getId());
					 List<SConstract> listSConstract = sConstractService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sConstractSch));
					 int accountSum = 0;int realAccount = 5000;
					 for (SConstract sConstract : listSConstract) {
						accountSum += Integer.parseInt(sConstract.getAccount());
					}
					 if(accountSum == 0)
						 accountSum = 10000;
					 result.put("realAccount", realAccount);
					 result.put("account", accountSum);
					
				}
			} catch (Exception e) {
				log.add(e.getMessage());
			}

			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
		@RequestMapping("/listTaskDetailSchedule.do")
		public @ResponseBody
		Map<String, Object> listTaskDetailSchedule(@RequestBody STaskScheduleSch TaskScheduleSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(TaskScheduleSch));
			
			//获取客户信息
			SCustomerSch customerSch = new SCustomerSch();
			customerSch.setIdSch(listSTaskSchedule.get(0).getCustomerId());
			List<SCustomer> listSCustomer = sCustomerService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(customerSch));
			
			listSTaskSchedule.get(0).setIsAllowSubmit(!TimeUtil.isAfterSomeHours(listSTaskSchedule.get(0).getRealFinishTime(), 24));
			
			RUserSch ContactUserSch = new RUserSch();
			ContactUserSch.setIdSch(listSCustomer.get(0).getUserId());
			List<RUser> listContactUsers = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(ContactUserSch));	
			listSCustomer.get(0).setContactUser(listContactUsers.get(0));
			
			result.put("customer", listSCustomer.get(0));
			 
			//根据客户找任务
			 STaskScheduleSch relativeTaskScheduleSch = new STaskScheduleSch();
			 relativeTaskScheduleSch.setCustomerIdSch(listSCustomer.get(0).getId());
			 List<STaskSchedule> relativeSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(relativeTaskScheduleSch));
			 
			 //给相应合同填充人
			 for (STaskSchedule sTaskSchedule : relativeSTaskSchedule) {
				 RUserSch rUserSch = new RUserSch();
				 rUserSch.setIdSch(sTaskSchedule.getExecutorId());
				 List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));	
				 sTaskSchedule.setUser(listRUser.get(0));
			 }
			 
			 //获取往来记录
			 result.put("record", relativeSTaskSchedule);
			 
			 //获取配置
			 if (listSCustomer.size()>0) {
				 SIndustryConfigSch SIndustryConfigSch = new SIndustryConfigSch();
				 SIndustryConfigSch.setCustomerIdSch(listSCustomer.get(0).getId());
				 List<SIndustryConfig> listSIndustryConfig = sIndustryConfigService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(SIndustryConfigSch));
				result.put("industryConfig", listSIndustryConfig.get(0));
			 }
			 res.put("result", result);
			 res.put("success", "true");
			 res.put("message", log);
			 return res;
		}
		
		
		@RequestMapping("/listTaskDetail.do")
		public @ResponseBody
		Map<String, Object> listTaskDetail(@RequestBody STaskScheduleSch TaskScheduleSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			//List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(TaskScheduleSch));
			STaskSchedule task = sTaskScheduleService.get(TaskScheduleSch.getIdSch());
			SysUploadSch sysUploadSch = new SysUploadSch();
            sysUploadSch.setModuleIdSch("taskDetail");
            sysUploadSch.setDataIdSch(Integer.toString(task.getId()));
            task.setIsAllowSubmit(!TimeUtil.isAfterSomeHours(task.getRealFinishTime(), 24));

            List<SysUpload> sysUploads = sysUploadService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sysUploadSch));
            List<String> liveSituationUrl = new ArrayList<>();
            List<String> processResultUrl = new ArrayList<>();
            List<String> visiteRecordUrl = new ArrayList<>();
            for (SysUpload sysUpload : sysUploads) {
                if (sysUpload.getFuncId().equals("processResult")) {
                    processResultUrl.add(sysUpload.getFilefullpath());
                }
                if (sysUpload.getFuncId().equals("liveSituation")) {
                    liveSituationUrl.add(sysUpload.getFilefullpath());
                }
                if (sysUpload.getFuncId().equals("visiteRecord")) {
                    visiteRecordUrl.add(sysUpload.getFilefullpath());
                }
                task.setLiveSituationUrl(liveSituationUrl);
                task.setProcessResultUrl(processResultUrl);
                task.setVisiteRecordUrl(visiteRecordUrl);
            }
			
			//获取客户信息
			SCustomerSch customerSch = new SCustomerSch();
			customerSch.setIdSch(task.getCustomerId());
			List<SCustomer> listSCustomer = sCustomerService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(customerSch));
			task.setsCustomers(listSCustomer);
			result.put("task", task );
			
			
			//根据客户找任务
			 STaskScheduleSch relativeTaskScheduleSch = new STaskScheduleSch();
			 relativeTaskScheduleSch.setCustomerIdSch(listSCustomer.get(0).getId());
			 List<STaskSchedule> relativeSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(relativeTaskScheduleSch));
			 //he
			 try 
			 {
				 STaskSchedule tatolrateTaskSchedule = (STaskSchedule)Config.cSql.excutSql("SELECT sum(t.rate) as rate from s_task_schedule t where t.executor_id = "+ task.getExecutorId() , new STaskSchedule()).get(0);
				 float tatolRate = Float.valueOf(tatolrateTaskSchedule.getRate());
				 STaskSchedule countTaskSchedule = (STaskSchedule)Config.cSql.excutSql("SELECT count(*) as rate from s_task_schedule t where t.executor_id ="+ task.getExecutorId() , new STaskSchedule()).get(0);
				 float aveRate = tatolRate/Float.valueOf(countTaskSchedule.getRate());
				 result.put("rate", aveRate);
			 } 
			 catch (Exception e) 
			 {
				result.put("rate", "0");
			 }
			 
		 
			 //给相应合同填充人
			 for (STaskSchedule sTaskSchedule : relativeSTaskSchedule) {
				 try {
					 RUserSch rUserSch = new RUserSch();
					 rUserSch.setIdSch(sTaskSchedule.getExecutorId());
					 List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));	
					 sTaskSchedule.setUser(listRUser.get(0));
				} catch (Exception e) {
					e.printStackTrace();
				}
				 
			 }
			 
			 //获取往来记录
			// result.put("record", relativeSTaskSchedule);
			 
			 //获取配置
			 if (listSCustomer.size()>0) {
				 SIndustryConfigSch SIndustryConfigSch = new SIndustryConfigSch();
				 SIndustryConfigSch.setCustomerIdSch(listSCustomer.get(0).getId());
				 List<SIndustryConfig> listSIndustryConfig = sIndustryConfigService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(SIndustryConfigSch));
				result.put("industryConfig", listSIndustryConfig.get(0));
			 }
			
			 result.put("contactPositionList", getSysClassesListById(83));
			 result.put("reimbureTypeList", getSysClassesListById(102));
			 result.put("departmentList", getSysClassesListById(99));
			 result.put("receiptTypeList",getSysClassesListById(105));
			 res.put("result", result);
			 res.put("success", "true");
			 res.put("message", log);
			 return res;
		}
		
		@RequestMapping("/getIndustryConfigByIdSchOfCustomer.do")
		public @ResponseBody
		Map<String, Object> getIndustryConfigByIdSchOfCustomer(@RequestBody SCustomerSch sCustomerSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
		
			List<String> log = new ArrayList<String>();
		//	STaskSchedule taskSchedule = sTaskScheduleService.get(taskScheduleSch.getIdSch());
			SCustomer sCustomer = sCustomerService.get(sCustomerSch.getIdSch());
			
			//获取配置列表
			SIndustryConfigSch SIndustryConfigSch = new SIndustryConfigSch();
			SIndustryConfigSch.setIdSch(sCustomer.getConfigId());
			List<SIndustryConfig> listSIndustryConfig = sIndustryConfigService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(SIndustryConfigSch));
			
			result.put("industryConfig", listSIndustryConfig.get(0));
			
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
		
		//其实提交的是taskId
		@RequestMapping("/getComeAndGoRecordByIdSchOfCustomer.do")
		public @ResponseBody
		Map<String, Object> getComeAndGoRecordByIdSchOfCustomer(@RequestBody SCustomerSch sCustomerSch  ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
		
			List<String> log = new ArrayList<String>();
			//获取和客户相关的任务以及用户：往来记录
			STaskScheduleSch sTaskScheduleSch1 = new STaskScheduleSch();
			//STaskSchedule sTaskSchedule = sTaskScheduleService.get(taskScheduleSch.getIdSch());
			sTaskScheduleSch1.setCustomerIdSch(sCustomerSch.getIdSch());
			List<STaskSchedule> comeAndGo = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch1));
			
			for (STaskSchedule sTaskSchedule2 : comeAndGo) {
				sTaskSchedule2.setUser(rUserService.get(sTaskSchedule2.getExecutorId()));
			}
			
			result.put("comeAndGoRecord", comeAndGo);
			
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
		@RequestMapping("/getCustomerDetailListByUserNameSch.do")
		public @ResponseBody
		Map<String, Object> getCustomerDetailListByUserNameSch(@RequestBody RUserSch rUserSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
			List<String> log = new ArrayList<String>();
			
			if (listRUser.size()>0) {
				RUser user = listRUser.get(0);
				List<SCustomer> listSCustomer = new ArrayList<SCustomer>();
				List<Integer>  customerIds = new ArrayList<Integer>();
				try {
				
					ExpressionQuery query = ExpressionQuery.buildQueryAll();
					List<Expression> expressions = new ArrayList<Expression>();
					expressions.add(new SqlExpression("id in(select min(id) from s_task_schedule group by customer_id) "));
					query.addAll(expressions);
					List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(query);
					
					
				//通过任务找到所有的客户
				for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
					SCustomer sCustomer= sCustomerService.get(sTaskSchedule.getCustomerId());
					listSCustomer.add(sCustomer);
					// 获得联系人信息
					 SContactSch sContactSch = new SContactSch();
					 sContactSch.setCustomerIdSch(sCustomer.getId());
					 List<SContact> sContacts = sContactService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sContactSch));
					 sCustomer.setsContact(sContacts.get(0));
				}
				result.put("customerList", listSCustomer);
				} catch (Exception e) {
					log.add(e.getMessage());
					e.printStackTrace();
				}
			}
			
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
		//其实传的是taskId
		@RequestMapping("/getCustomerDetailListByIdSchOfCustomer.do")
		public @ResponseBody
		Map<String, Object> getCustomerDetailListByIdSchOfCustomer(@RequestBody SCustomerSch sCustomerSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			try {
//				STaskSchedule taskSchedule = sTaskScheduleService.get(sCustomerSch.getIdSch());
				SCustomer sCustomer= sCustomerService.get(sCustomerSch.getIdSch());
				// 获得联系人信息
				 SContactSch sContactSch = new SContactSch();
				 sContactSch.setCustomerIdSch(sCustomer.getId());
				 List<SContact> sContacts = sContactService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sContactSch));
				 sCustomer.setsContact(sContacts.get(0));
				 result.put("customer", sCustomer);
			}
			 catch (Exception e) {
				log.add("获取联系人失败！");
				e.printStackTrace();
			}
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
		@RequestMapping("/listCustomerByUserNameSch.do")
		public @ResponseBody
		Map<String, Object> listCustomerByUserName(@RequestBody RUserSch rUserSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
			List<RUser> associationUser =new ArrayList<RUser>();
			List<String> log = new ArrayList<String>();
			
			if (listRUser.size()>0) {
				RUser user = listRUser.get(0);
				List<SCustomer> listSCustomer = new ArrayList<SCustomer>();
				//获取任务
				STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
				sTaskScheduleSch.setExecutorIdSch(user.getId());
				List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
				List<Integer>  customerIds = new ArrayList<Integer>();
				try {
				//通过任务找到所有的客户
				for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
					SCustomerSch customerSch = new SCustomerSch();
					customerSch.setIdSch(sTaskSchedule.getCustomerId());
					SCustomer sCustomer= sCustomerService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(customerSch)).get(0);
					
					// 获得联系人信息
					 SContactSch sContactSch = new SContactSch();
					 sContactSch.setIdSch(sCustomer.getUserId());
					 List<SContact> sContacts = sContactService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sContactSch));
					 sCustomer.setsContact(sContacts.get(0));
					
					//获取配置列表
					SIndustryConfigSch SIndustryConfigSch = new SIndustryConfigSch();
					SIndustryConfigSch.setIdSch(sCustomer.getConfigId());
					List<SIndustryConfig> listSIndustryConfig = sIndustryConfigService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(SIndustryConfigSch));
					
					
					
					//添加客户和配置
					sCustomer.setsIndustryConfig(listSIndustryConfig.get(0));
					
					if (customerIds.indexOf(sCustomer.getId()) == -1) {
						customerIds.add(sCustomer.getId());
						listSCustomer.add(sCustomer);
						//获取和客户相关的任务以及用户：往来记录
						STaskScheduleSch sTaskScheduleSch1 = new STaskScheduleSch();
						sTaskScheduleSch1.setCustomerIdSch(sCustomer.getId());
						List<STaskSchedule> comeAndGo = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch1));
						
						for (STaskSchedule sTaskSchedule2 : comeAndGo) {
							RUserSch aUserSch = new RUserSch();
							aUserSch.setIdSch(sTaskSchedule2.getExecutorId());
							List<RUser> ARUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
							sTaskSchedule2.setUser(ARUser.get(0));
						}
						sCustomer.setsTaskSchedules(comeAndGo);
					}
					
				}
				result.put("customerList", listSCustomer);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
		@RequestMapping("/listCommentByTaskId.do")
		public @ResponseBody
		Map<String, Object> listCommentByTaskId(@RequestBody STaskScheduleSch taskScheduleSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();

			List<STaskSchedule> taskSchedules = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(taskScheduleSch));
			List<String> log = new ArrayList<String>();
			
			if (taskSchedules.size()>0) {
				//获取客户信息
				SCustomerSch customerSch = new SCustomerSch();
				customerSch.setIdSch(taskSchedules.get(0).getCustomerId());
				List<SCustomer> listSCustomer = sCustomerService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(customerSch));
				
				//根据客户找任务
				 STaskScheduleSch relativeTaskScheduleSch = new STaskScheduleSch();
				 relativeTaskScheduleSch.setCustomerIdSch(listSCustomer.get(0).getId());
				 List<STaskSchedule> relativeSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(relativeTaskScheduleSch));
				
				 for (STaskSchedule sTaskSchedule : relativeSTaskSchedule) {
					RUserSch userSch = new RUserSch();
					userSch.setIdSch(sTaskSchedule.getExecutorId());
					List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(userSch));
					sTaskSchedule.setUser(listRUser.get(0));
				}

			   result.put("comment", relativeSTaskSchedule);
			
			}
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		



 @RequestMapping("/setReimburse.do")
	public @ResponseBody
	Map<String, Object> setReimburse(@RequestBody ReqReimburse reqReimburse) {
		Map<String, Object> res = new HashMap();
		List<String> log = new ArrayList<String>();
		List<ReqTicket> reqTickets = reqReimburse.getReqTickets();
		
		//获取任务并添加合同ID（令其包涵合同ID和任务ID）
		STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
		sTaskScheduleSch.setIdSch(reqReimburse.getTaskId());
		List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
		reqReimburse.setConstractId(listSTaskSchedule.get(0).getContractId());
		reqReimburse.setApplyId(listSTaskSchedule.get(0).getExecutorId());
		reqReimburse.setVarifyId(listSTaskSchedule.get(0).getUserId());
		
		//根据金额列表存储报销数据	
		for (ReqTicket reqTicket : reqTickets) {
			reqReimburse.setTicketNumber(reqTicket.getTicketNumber());
			reqReimburse.setAmount(reqTicket.getAmount());
			sReimburseService.save(reqReimburse);
			reqReimburse.setId(null);
		}
		res.put("success", "true");
		res.put("message", log);
		return res;
	}	
	 
	 @RequestMapping("/setReceipt.do")
		public @ResponseBody
		Map<String, Object> setReceipt(@RequestBody ReqReceipt reqReceipt) {
			Map<String, Object> res = new HashMap();
			List<String> log = new ArrayList<String>();
			List<ReqTicket> reqTickets = reqReceipt.getReqTickets();
			
			//获取任务并添加合同ID（令其包涵合同ID和任务ID）
			STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
			sTaskScheduleSch.setIdSch(reqReceipt.getTaskId());
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
			reqReceipt.setConstractId(listSTaskSchedule.get(0).getContractId());
			reqReceipt.setApplyId(listSTaskSchedule.get(0).getExecutorId());
			reqReceipt.setVarifyId(listSTaskSchedule.get(0).getUserId());
			//根据金额列表存储报销数据	
			for (ReqTicket reqTicket : reqTickets) {
				reqReceipt.setTicketNumber(reqTicket.getTicketNumber());
				reqReceipt.setAmount(reqTicket.getAmount());
				SReceiptService.save(reqReceipt);
				reqReceipt.setId(null);
			}
			res.put("success", "true");
			res.put("message", log);
			return res;
		}	
	 	@RequestMapping("/setConstact.do")
		public @ResponseBody
		Map<String, Object> setConstact(@RequestBody SContact reqContact) {
			Map<String, Object> res = new HashMap();
			List<String> log = new ArrayList<String>();
			
			//获取任务并添加合同ID（令其包涵合同ID和任务ID）
			STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
			sTaskScheduleSch.setIdSch(reqContact.getTaskId());
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
			reqContact.setCustomerId(listSTaskSchedule.get(0).getCustomerId());
			sContactService.save(reqContact);
			
			res.put("success", "true");
			res.put("message", log);
			return res;
		}	

	 	
		//合同列表里的合同任务接口
	 	@RequestMapping("/listTaskConstractIdSch.do")
		public @ResponseBody
		Map<String, Object> listTaskConstractIdSch(@RequestBody SConstractSch sConstractSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			//根据合同获取任务列表
			STaskScheduleSch sTaskScheduleSch = new STaskScheduleSch();
			sTaskScheduleSch.setContractIdSch(sConstractSch.getIdSch());
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sTaskScheduleSch));
			//添加对应的人
			for (STaskSchedule sTaskSchedule : listSTaskSchedule) {
				//添加发布者
				RUserSch rUserSch = new RUserSch();
				rUserSch.setIdSch(sTaskSchedule.getUserId());
				List<RUser> listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
				sTaskSchedule.setUser(listRUser.get(0));
				//添加执行人
				rUserSch.setIdSch(sTaskSchedule.getExecutorId());
				listRUser = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(rUserSch));
				sTaskSchedule.setExecutor(listRUser.get(0));
			}
			result.put("constractTask", listSTaskSchedule);
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		//根据合同ID获取收款信息
		@RequestMapping("/listReceiptByConstractIdSch.do")
		public @ResponseBody
		Map<String, Object> listReceiptByConstractIdSch(@RequestBody SReceiptSch sReceiptSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			//直接检索
			List<SReceipt> sReceipts = SReceiptService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sReceiptSch));
			result.put("executor", "未知");
			result.put("receipts", sReceipts);
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		//根据合同ID获取报销信息
		@RequestMapping("/listReimburseByConstractIdSch.do")
		public @ResponseBody
		Map<String, Object> listReimburseByConstractIdSch(@RequestBody SReimburseSch sReimburseSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			//直接检索
			List<SReimburse> sReimburse = sReimburseService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sReimburseSch));
			for (SReimburse sReimburse2 : sReimburse) {
				UserSch userSch = new UserSch();
				userSch.setIdSch(sReimburse2.getApplyId());
				List<RUser> users = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(userSch));
				sReimburse2.setExcutor(users.get(0));
			}
			
			result.put("reimburse", sReimburse);
			result.put("drawer", "未知");
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		//根据任务ID获取报销信息
		@RequestMapping("/listReimburseByTaskIdSch.do")
		public @ResponseBody
		Map<String, Object> listReimburseByTaskIdSch(@RequestBody SReimburseSch sReimburseSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			List<String> log = new ArrayList<String>();
			//直接检索
			List<SReimburse> sReimburse = sReimburseService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sReimburseSch));
			for (SReimburse sReimburse2 : sReimburse) {
				UserSch userSch = new UserSch();
				userSch.setIdSch(sReimburse2.getApplyId());
				List<RUser> users = rUserService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(userSch));
				sReimburse2.setExcutor(users.get(0));
			}
			
			result.put("reimburse", sReimburse);
			result.put("drawer", "未知");
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		
	
		//根据任务ID获取联系人列表
		@RequestMapping("/listContactByTaskIdSch.do")
		public @ResponseBody
		Map<String, Object> listContactByConstractIdSch(@RequestBody SContactSch sContactSch ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();

			List<SContact> listSContact = sContactService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sContactSch));
			List<String> log = new ArrayList<String>();
			
			result.put("contact", listSContact);
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		//接收处理结果：
		@RequestMapping("/getFeedBack.do")
		public @ResponseBody
		Map<String, Object> setProcessResult(ReqFeedBack feedback, HttpServletRequest request ) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			STaskScheduleSch taskScheduleSch = new STaskScheduleSch();
			taskScheduleSch.setIdSch(Integer.valueOf(feedback.getTaskId()));
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(taskScheduleSch));
			List<String> log = new ArrayList<String>();
			
			if (listSTaskSchedule.size()!=0) {
				STaskSchedule sTaskSchedule = listSTaskSchedule.get(0);
				if (feedback.getProcessResult()!=null) {
					 sTaskSchedule.setProcessResult(feedback.getProcessResult());
				}
				if (feedback.getLiveSituation()!=null) {
					 sTaskSchedule.setLiveSituation(feedback.getLiveSituation());

				}
				if (feedback.getVisiteRecord()!=null) {
					 sTaskSchedule.setVisiteRecord(feedback.getVisiteRecord().toString());
				}
				sTaskScheduleService.update(sTaskSchedule);
				upload(feedback , request);
				
			}
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		}
		

 @RequestMapping(value = "/upload.do")
 public  @ResponseBody String upload(@RequestBody SysUpload upload , HttpServletRequest request) {
        System.out.println("开始");
//		String path = request.getSession().getServletContext().getRealPath("/uploadfiles/");  
//		String fileName = upload.getFile().getOriginalFilename();
       
        String path = Config.FILEROOT;
        System.out.println(request.getSession().getServletContext().getRealPath("/uploadfiles/"));
        MultipartHttpServletRequest multipartRequest  =  (MultipartHttpServletRequest) request;  
        Map<String,MultipartFile> fileMap  =multipartRequest.getFileMap();
       // String realPath = request.getSession().getServletContext().getRealPath("/uploadfiles");
        for (String key : fileMap.keySet()) {
        	 String fileName = key;
        	 File targetFile = new File(path, fileName);
        	 upload.setServername(path);
        	 upload.setFilefullpath("/uploadfiles/"+fileName);
        	 if(!targetFile.exists())
        	 {
		            targetFile.mkdirs();
		      }
        	//保存
	        try 
	        {
	        	fileMap.get(key).transferTo(targetFile);
	        	sysUploadService.save(upload);
	        } 
	        catch (Exception e) 
	        {
	            e.printStackTrace();
	        } 
        	 
        }
        return "success";
    }	
 
 	//接收处理结果：
	@RequestMapping("/getFeedBackFromiOS.do")
	public @ResponseBody
	Map<String, Object> getFeedBackFromIOS(ReqFeedBack feedback, HttpServletRequest request ) {
		Map<String, Object> res = new HashMap();
		try {
			Map<String, Object> result = new HashMap();
			STaskScheduleSch taskScheduleSch = new STaskScheduleSch();
			taskScheduleSch.setIdSch(Integer.valueOf(feedback.getTaskId()));
			List<STaskSchedule> listSTaskSchedule = sTaskScheduleService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(taskScheduleSch));
			List<String> log = new ArrayList<String>();
			
			if (listSTaskSchedule.size()!=0) {
				STaskSchedule sTaskSchedule = listSTaskSchedule.get(0);
				if (feedback.getProcessResult()!=null) {
					 sTaskSchedule.setProcessResult(feedback.getProcessResult());
				}
				if (feedback.getLiveSituation()!=null) {
					 sTaskSchedule.setLiveSituation(feedback.getLiveSituation());
	
				}
				if (feedback.getVisiteRecord()!=null) {
					 sTaskSchedule.setVisiteRecord(feedback.getVisiteRecord().toString());
				}
				sTaskScheduleService.update(sTaskSchedule);
				uploadiOS(feedback , request);
				
			}
			res.put("result", result);
			res.put("success", "true");
			res.put("message", log);
			return res;
		} catch (Exception e) {
			res.put("error", e.getMessage());
			return res;
		}
	}
	
		@RequestMapping(value = "/uploadiOS.do")
		 public  @ResponseBody String uploadiOS(@RequestBody SysUpload upload , HttpServletRequest request) {
		        System.out.println("开始");
		        String path = Config.FILEROOT;
		        System.out.println(path);
		        MultipartHttpServletRequest multipartRequest  =  (MultipartHttpServletRequest) request;  
		        MultipartFile[] files  = upload.getPics();
		        for (MultipartFile file : files) {
		        	 File targetFile = new File(path, file.getOriginalFilename());
		        	 upload.setServername(path);
		        	 upload.setFilefullpath("/uploadfiles/"+file.getOriginalFilename());
		        	 if(!targetFile.exists())
		        	 {
				            targetFile.mkdirs();
				      }
		        	//保存
			        try 
			        {
			        	file.transferTo(targetFile);
			        	sysUploadService.save(upload);
			        } 
			        catch (Exception e) 
			        {
			            e.printStackTrace();
			        } 
		        	 
		        }
		        return "success";
		    }	

		@RequestMapping(value = "/getJpushMessgeListByReceiveIdSch.do")
		 public  @ResponseBody Map<String, Object> getJpushMessge(@RequestBody SMessageSch sMessageSch) {
			Map<String, Object> res = new HashMap();
			Map<String, Object> result = new HashMap();
			sMessageSch.setSendTypeSch("Jpush");
			List<SMessage> listMessge = sMessageService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sMessageSch));
			result.put("MessageList", listMessge);
			res.put("result", result);
			return res;
		}
		       
 
	
	@RequestMapping("/getSysClassesList.do")
	public @ResponseBody
	Map<String, Object> getSysClassesList(@RequestBody SysClassSch sysClassSch ) {
		Map<String, Object> res = new HashMap();
		Map<String, Object> result = new HashMap();
		List<SysClass> sysClasses = sysClassService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sysClassSch));
		result.put("sysClasses", sysClasses);
		res.put("result", result);
		res.put("success", "true");
		return res;
	}
	
	@RequestMapping("/getSysClassesListById.do")
	public @ResponseBody
	Object getSysClassesListById(int typeId) {
		Map<String, Object> res = new HashMap();
		SysClassSch sysClassSch = new SysClassSch();
		sysClassSch.setParentIdSch(typeId);
		List<SysClass> sysClasses = sysClassService.find(ExpressionQuery.buildQueryAll().addAnnotionExpression(sysClassSch));
		return sysClasses;
	}

		 
}
